package com.neusoft.elmboot.controller;

import java.util.List;

import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.util.response.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.service.BusinessService;

@RestController
@RequestMapping("/elm/BusinessController")
public class BusinessController {
	
	@Autowired
	private BusinessService businessService;
	
	@RequestMapping("/listBusinessByOrderTypeId")
	public List<Business> listBusinessByOrderTypeId(Business business) throws Exception{
		return businessService.listBusinessByOrderTypeId(business.getOrderTypeId());
	}
	
	@RequestMapping("/getBusinessById")
	public Business getBusinessById(Business business) throws Exception{
		return businessService.getBusinessById(business.getBusinessId());
	}

//	@RequestMapping("/business/login")
//	public ResultBody businessLogIn (@RequestParam Integer businessId,
//									 @RequestParam String password) throws Exception{
//		try {
//			String pwd = businessService.getPasswordByBusinessId(businessId);
//			if (pwd.equals(password)) {
//				return ResultBody.success("商家登录成功！", true);
//			}
//			return ResultBody.error("账号或密码错误！", false);
//		} catch (Exception e) {
//			return ResultBody.error("登录失败！", false);
//		}
//
//	}
//
//	@RequestMapping("/business/changePwd")
//	public ResultBody changePwd(@RequestParam Integer businessId,
//								@RequestParam String oldPassword,
//								@RequestParam String newPassword) throws Exception{
//		try {
//			if (newPassword.length() >20 || newPassword.length() < 6) {
//				return ResultBody.error("密码长度不符合要求，应为6~20位", null);
//			}
//
//			if (!newPassword.matches("^[A-Za-z0-9]+$")) {
//				return ResultBody.error("密码只能包含数字和大小写字母", null);
//			}
//
//			String pwd = businessService.getPasswordByBusinessId(businessId);
//			if (pwd.equals(oldPassword)) {
//				businessService.updatePwd(businessId, newPassword);
//				return ResultBody.success("修改密码成功！", null);
//			}
//			return ResultBody.error("原始密码错误！", null);
//		} catch (Exception e) {
//			return ResultBody.error("修改密码失败！", null);
//		}
//	}

}
